#!/bin/bash
if [ $# -ne 2 ]
then
    echo "useage $0 dir wold"
    echo "举例 $0 test wangrui"
    exit 1
fi

if [ -d $1 ]
then
    cd $1
else
    echo "$1 不存在"
    exit 1
fi

for file in `ls .`
do
    if [ -d $file ]
    then
        if [ -f $file/text.txt ]
        then
            n=`grep -cw $2 $file/text.txt`
            echo "$1/$file/text.txt中，有$n个$2"
        else
            echo "$1/$file/ 下面没有 text.txt"
        fi
    fi
done